﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;

public partial class UserAuditList : Acms.AcmsControls.ContentControls.Admin.BaseCustomAdminControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    public int UserId { get; private set; }
    protected override object SaveViewState()
    {
        ViewState["UserId"] = UserId;
        return base.SaveViewState();
    }
    protected override void LoadViewState(object savedState)
    {
        base.LoadViewState(savedState);
        if (ViewState["UserId"] is int)
        {
            UserId = (int)ViewState["UserId"];
        }
    }
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        ds.Select += new EventHandler<Acms.DataControls.EventDrivenDataSourceSelectEventArgs>(ds_Select);
        grid.MasterTableView.Columns.OfType<GridHyperLinkColumn>().Where(x => x.Text == "View").Single().DataNavigateUrlFormatString = base.ResolveCustomControlPath("~/UserAuditSections.ascx?Id={0}");
        if (!IsPostBack)
        {
            try
            {
                UserId = int.Parse(Request.QueryString["Id"]);
            }
            catch (FormatException) { }
            catch (ArgumentNullException) { }
        }
    }


    void ds_Select(object sender, Acms.DataControls.EventDrivenDataSourceSelectEventArgs e)
    {
        CarbonExchange.Bll.AuditFactory factory = new CarbonExchange.Bll.AuditFactory();
        e.SetData(factory.GetAllByUserId(UserId));
    }

    public override void GetExtaBreadCrumbs(Dictionary<string, string> extaItems)
    {
        if (UserId > 0)
        {
            var tmp = Acms.Bll.User.GetById(UserId);
            if (tmp != null)
            {
                extaItems.Add(tmp.DisplayName, AcmsContext.OriginalUrl);
            }
        }
    }
}
